package com.ruoyi.ams.controller;

import com.ruoyi.ams.domain.AmsAssetInventorySurplus;
import com.ruoyi.ams.service.IAmsAssetInventorySurplusService;
import com.ruoyi.common.core.domain.KeyValueVo;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.security.annotation.PreAuthorize;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 盘盈Controller
 * 
 * @author yfkj
 * @date 2022-05-16
 */
@RestController
@RequestMapping("/ams/surplus")
public class AmsAssetInventorySurplusController extends BaseController
{
    @Autowired
    private IAmsAssetInventorySurplusService amsAssetInventorySurplusService;

    /**
     * 查询盘盈列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:surplus:list")
    //@ApiOperation(value = "获取盘盈列表")
    @GetMapping("/getAmsAssetInventorySurplusList")
    public TableDataInfo getAmsAssetInventorySurplusList(AmsAssetInventorySurplus amsAssetInventorySurplus)
    {
        startPage();
        List<AmsAssetInventorySurplus> list = amsAssetInventorySurplusService.selectAmsAssetInventorySurplusList(amsAssetInventorySurplus);
        return getDataTable(list);
    }


    /**
     * 获取盘盈详细信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:surplus:query")
    //@ApiOperation(value = "获取盘盈详情")
    @GetMapping(value = "/getAmsAssetInventorySurplusById")
    public AjaxResult getAmsAssetInventorySurplusById(@RequestParam("inventorySurplusId") Long inventorySurplusId)
    {
        return AjaxResult.success(amsAssetInventorySurplusService.selectAmsAssetInventorySurplusByInventorySurplusId(inventorySurplusId));
    }

    /**
     * 新增盘盈
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:surplus:add")
    @Log(title = "盘盈", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增盘盈")
    @PostMapping(value = "/addAmsAssetInventorySurplus")
    public AjaxResult addAmsAssetInventorySurplus(@RequestBody AmsAssetInventorySurplus amsAssetInventorySurplus)
    {
        return toAjax(amsAssetInventorySurplusService.save(amsAssetInventorySurplus));
    }

    /**
     * 修改盘盈
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:surplus:edit")
    @Log(title = "盘盈", businessType = BusinessType.UPDATE)
    //@ApiOperation(value = "修改盘盈")
    @PostMapping(value = "/editAmsAssetInventorySurplus")
    public AjaxResult editAmsAssetInventorySurplus(@RequestBody AmsAssetInventorySurplus amsAssetInventorySurplus)
    {
        return toAjax(amsAssetInventorySurplusService.updateAmsAssetInventorySurplus(amsAssetInventorySurplus));
    }

    /**
     * 删除盘盈
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:surplus:remove")
    @Log(title = "盘盈", businessType = BusinessType.DELETE)
	@GetMapping("/removeAmsAssetInventorySurpluss")
    public AjaxResult removeAmsAssetInventorySurpluss(@RequestParam Long[] inventorySurplusIds)
    {
        return toAjax(amsAssetInventorySurplusService.deleteAmsAssetInventorySurplusByInventorySurplusIds(inventorySurplusIds));
    }
    @GetMapping("/getAmsAssetInventorySurplusNamesForSelect")
    //@ApiOperation(value = "获取盘盈名称列表用于下拉搜索")
    public AjaxResult getAmsAssetInventorySurplusNamesForSelect()
    {
        List<AmsAssetInventorySurplus> list = amsAssetInventorySurplusService.list();//自行加条件
        List<KeyValueVo> resultList = new ArrayList<>();
        for (AmsAssetInventorySurplus amsAssetInventorySurplus: list ) {
            KeyValueVo vo = new KeyValueVo();
            //vo.setKey(it.getId());
            //vo.setValue(it.getName());
            resultList.add(vo);
        }
        return AjaxResult.success(resultList);
    }
    /**
     * 导出盘盈列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:surplus:export")
    @Log(title = "盘盈", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAmsAssetInventorySurplus")
    public String exportAmsAssetInventorySurplus(HttpServletResponse response, AmsAssetInventorySurplus amsAssetInventorySurplus) throws IOException
    {
        List<AmsAssetInventorySurplus> list = amsAssetInventorySurplusService.selectAmsAssetInventorySurplusList(amsAssetInventorySurplus);
        ExcelUtil<AmsAssetInventorySurplus> util = new ExcelUtil<AmsAssetInventorySurplus>(AmsAssetInventorySurplus.class);
        util.exportExcel(response, list, "盘盈数据");
        return "";
    }

}
